
import Vue from 'vue'
const state = {
    autocompleteList: {
        // partNumber: [{ value: "ljh" }, { value: "1ljh" }, { value: "2ljh" }]
    },
}
const mutations = {
    setList(state, data) {
        const { name, value } = data
        // 存在当前的对象
        if (state.autocompleteList[name]) {
            // 存储长度等于5的时候 不在添加 覆盖第一条
            if (state.autocompleteList[name].length >= 5) {
                Vue.set(state.autocompleteList[name], 0, { value })
                return
            }
            // 存在的就不重复添加
            const isExistence = state.autocompleteList[name].find(item => item.value === value)
            if (isExistence) {
                return
            }
            // 不存在添加
            state.autocompleteList[name].push({
                value
            })
        } else {
            state.autocompleteList[name] = [{ value }]
        }
    }
}

const actions = {
}

export default {
    namespaced: true,
    state,
    mutations,
    actions
}

